package com.ishowcode.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    //定义队列名
    private static final String QUEUE = "queue";
    private static final String QUEUE1 = "queue1";
    private static final String QUEUE2 = "queue2";
    private static final String EXCHANGE = "exchange";
    private static final String EXCHANGE_DIRECT = "exchange_direct";
    private static final String QUEUE_DIRECT1 = "direct1";
    private static final String QUEUE_DIRECT2 = "direct2";
    private static final String ROUTING_KRY1 = "routing1";
    private static final String ROUTING_KRY2 = "routing2";
    //创建队列
    @Bean
    public Queue queue(){
        //true表示是否持久化
        return new Queue(QUEUE,true);
    }
    //创建队列
    @Bean
    public Queue queue1(){
        //true表示是否持久化
        return new Queue(QUEUE1);
    }
    //创建队列
    @Bean
    public Queue queue2(){
        //true表示是否持久化
        return new Queue(QUEUE2,true);
    }
    //创建交换机
    @Bean
    public FanoutExchange exchange(){
        //true表示是否持久化
        return new FanoutExchange(EXCHANGE);
    }
    //绑定队列到交换机
    @Bean
    public Binding binding1(){
        //true表示是否持久化
        return BindingBuilder.bind(queue1()).to(exchange());
    }
    @Bean
    public Binding binding2(){
        //true表示是否持久化
        return BindingBuilder.bind(queue2()).to(exchange());
    }
    @Bean
    public Queue queue_direct1(){
        //true表示是否持久化
        return new Queue(QUEUE_DIRECT1,true);
    }
    @Bean
    public Queue queue_direct2(){
        //true表示是否持久化
        return new Queue(QUEUE_DIRECT2,true);
    }
    @Bean
    public DirectExchange direct_exchange(){
        //true表示是否持久化
        return new DirectExchange(EXCHANGE_DIRECT);
    }
    @Bean
    public Binding binding_direct1(){
        //true表示是否持久化
        return BindingBuilder.bind(queue_direct1()).to(direct_exchange()).with(ROUTING_KRY1);
    }
    @Bean
    public Binding binding_direct2(){
        //true表示是否持久化
        return BindingBuilder.bind(queue_direct2()).to(direct_exchange()).with(ROUTING_KRY2);
    }
}
